package trefliq.EJB.entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;

/**
 *
 * @author Eric
 */
@Entity
@NamedQuery(name="findAllRatings", query="select r from Rating r")
public class Rating implements Serializable {
    
    public enum Code {
        NULL, G, PG, PG13, R, X, NC17, NR
    }
    
    @Id
    private Code code;
    
    @Column(length=5)
    private String codeText;
    
    @Column(length=2000)
    private String description;
    
    public Rating() {
    }

    public Rating(Rating o) {
        code = o.code;
        codeText = o.codeText;
        description = o.description;
    }

    
    public Rating(Code code) {
        this.code = code;
    }
    
    public Code getCode() {
        return code;
    }
    
    public void setCode(Code code) {
        this.code = code;
    }
    
    public String getCodeText() {
        return codeText;
    }
    
    public void setCodeText(String codeText) {
        this.codeText = codeText;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (code != null ? code.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rating)) {
            return false;
        }
        Rating other = (Rating) object;
        if ((this.code == null && other.code != null) || (this.code != null && !this.code.equals(other.code))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        
        String codeStr;
        switch (code){
            case G: codeStr = "G"; break;
            case PG: codeStr = "PG"; break;
            case PG13: codeStr = "PG-13"; break;
            case R: codeStr = "R"; break;
            case X: codeStr = "X"; break;
            case NC17: codeStr = "NC-17"; break;
            case NR: codeStr = "NR"; break;
                
            default: codeStr = "Invalid code";
        }
        
        return "trefliq.persistence.entity.Rating[ code=" + codeStr + " ] actual[" + codeText + "] description[" + description +"]";
    }
}